window.onload = function () {
    // dom获取
    let username = document.querySelector('[name="username"]')
    let password = document.querySelector('[name="password"]')
    let form = document.querySelector('form')
    let toRegister = document.querySelector('.toregister')
    // 页面样式处理
    // 业务处理
    // 登录页跳转
    toRegister.onclick = () => {
        location.href = '/register.html'
    }
    // 登录
    form.onsubmit = () => {
        promiseRequest({
            method: 'post',
            url: '/front/api/user/login',
            data: {
                username: username.value,
                password: password.value
            }
        }).then(res => {
            if (res.error_code === 200) {
                // 存cookie
                setCookie('username', username.value, 7200)
                popup.msg(res.msg, () => {
                    location.href = '/index.html'
                })
            } else {
                popup(res.msg)
            }
        })
        return false
    }

}